package com.sunedai.tiger.web.controller.emp.system;

import com.sunedai.tiger.dao.system.entity.EmpUsr;
import com.sunedai.tiger.service.system.EmpUsrService;
import com.sunedai.tiger.web.controller.emp.BaseEmpController;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户控制器
 * @author zhaolipeng
 */
@Controller
@RequestMapping("/emp/sys/usr")
public class EmpUsrController extends BaseEmpController {

  @Resource
  private EmpUsrService empUsrService;

  @GetMapping
  public ModelAndView usr() {
    ModelAndView view = new ModelAndView("sys.usr");
    view.addObject("totalRecords", empUsrService.count());
    return view;
  }

  @GetMapping("/list")
  @ResponseBody
  public List<EmpUsr> list(@RequestParam int p, @RequestParam int max) {
    return empUsrService.list(p, max);
  }

  @PostMapping("/save_update")
  @ResponseBody
  public EmpUsr saveOrUpdate(@Validated @ModelAttribute EmpUsr empUsr) {
    return empUsrService.saveOrUpdate(empUsr, getLoginUsrId());
  }
}
